package com.sevencar.activity;


import com.example.lightble.CmdSend;
import com.example.lightble.R;
import com.sevencar.util.ToastUtil;

import me.maxwin.view.SnoSeekBarDialog;
import me.maxwin.view.SnoSeekBarDialog.OnOkPressedListener;
import me.maxwin.view.TopIndicator;
import me.maxwin.view.TopIndicator.OnTopIndicatorListener;
import me.maxwin.view.XListView.IXListViewListener;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class OrderManageFragment extends Fragment implements IXListViewListener {
	
	// �龰
	private Activity mActivity;
	private TextView mTitleTv;
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.mActivity = activity;
	}

	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		
		return inflater.inflate(R.layout.fragment_order, container, false);
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
	}
	
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		initViews(view);
	}
	private void initViews(View view) {
		RelativeLayout re_group_color = (RelativeLayout)view.findViewById(R.id.re_group_color);
		re_group_color.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent _intent = new Intent(getActivity(),SelectMoreColorActivity.class);
				startActivity(_intent);
			}
		});
		RelativeLayout re_tiao = (RelativeLayout)view.findViewById(R.id.re_tiao);
		re_tiao.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				isTiaobianOpen=!isTiaobianOpen;
				showSeekbarDialog(1);
			}
		});
		RelativeLayout re_jian = (RelativeLayout)view.findViewById(R.id.re_jian);
		re_jian.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				isJianBianOpen=!isJianBianOpen;
				showSeekbarDialog(0);
			}
		});
		
		
		
		
		
	}
	
	
	
	@Override
	public void onRefresh() {
		
	}

	@Override
	public void onLoadMore() {
		
	}

	boolean isJianBianOpen,isTiaobianOpen;
	 byte     jianbianSecond,tiaobianSecond;
	 
	private void showSeekbarDialog(int resId)
	{
		SnoSeekBarDialog mSnoSeekBarDialog =new SnoSeekBarDialog(mActivity,resId);

		mSnoSeekBarDialog.setOnOkPressedListener(new OnOkPressedListener() {
			
			public void changed(AlertDialog dialog, int resId, int progress) {
				if(resId==0){
					
					float second=(float)(progress);
					float second2=second/2;
					String str=String.format("%.1f",second2);
					
					str+="秒";
//					jianbianTime.setText(str);
					jianbianSecond=(byte) progress;
					
					HomeFragment.mBLEServiceInstance.sendData(CmdSend.getInstance().getJianBianArray(isJianBianOpen,jianbianSecond));
					
//					sendPackage();
					
					
					
				}else if(resId==1){
					
					float second=(float)(progress);
					float second2=second/2;
					String str=String.format("%.1f",second2);
					str+="秒";
//					tiaobianTime.setText(str);
					tiaobianSecond=(byte) progress;
					HomeFragment.mBLEServiceInstance.sendData(CmdSend.getInstance().getTiaoBianArray(isTiaobianOpen,tiaobianSecond));
				}
			}
		});
		Toast.makeText(getActivity(), "hello", 1000).show();
		mSnoSeekBarDialog.show();
	}

	private void updateJianbianSwitchs()
	{
//		jianbianSwitch.setBackground(getResources().getDrawable(R.drawable.switch_off)); 
//		tiaobianSwitch.setBackground(getResources().getDrawable(R.drawable.switch_off)); 
		if(isJianBianOpen){
//			jianbianSwitch.setBackground(getResources().getDrawable(R.drawable.switch_on)); 
			isTiaobianOpen=false;
		}
	}
	private void updateTiaobianSwitchs()
	{
//		jianbianSwitch.setBackground(getResources().getDrawable(R.drawable.switch_off)); 
//		tiaobianSwitch.setBackground(getResources().getDrawable(R.drawable.switch_off)); 
	    if(isTiaobianOpen){
//			tiaobianSwitch.setBackground(getResources().getDrawable(R.drawable.switch_on));
			isJianBianOpen=false;
		}
	}
}
